package com.ztesoft.book.admin.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * @Description Swagger3.0配置类
 * @Author YangFan
 * @Date 2021-04-15 15:35
 */
@Configuration
public class Swagger3Config implements WebMvcConfigurer {

    @Value("${book.swagger.enable}")
    private Boolean enable;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .enable(enable)
                .useDefaultResponseMessages(false)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any())
                .build();

        // // 授权信息设置，必要的header token等认证信息
        // .securitySchemes(securitySchemes())
        // // 授权信息全局应用
        // .securityContexts(securityContexts());
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("Swagger3接口文档")
                .description("了解更多请咨询服务开发者 ！")
                .contact(new Contact("GZ_BOOK_ADMIN", "https://www.baidu.com/", "526186881@qq.com"))
                .version("1.0")
                .build();
    }

}